<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Controller\AuthController;
use Think\Auth;
use Vendor\ThinkImage\ThinkImage;

class MemberController extends AuthController {

    public function index(){

        $key=I('key');

        if($key&&$key!=""){
            $map = array(
                'user_number' =>array('like', $key),
                'username'=>array('like', $key),                
                '_logic'     =>'or',
            );
            
        }

        $sldate=urldecode(I('reservation',''));//获取格式 2015-11-12 - 2015-11-18
        $arr = explode(" - ",$sldate);//转换成数组
        $arrdateone=strtotime($arr[0]);
        $arrdatetwo=strtotime($arr[1].' 23:55:55');  
        //var_dump($arrdateone);exit;
        if($arrdateone && $arrdatetwo){
            $map['birthdate'] = array(array('egt',$arrdateone),array('elt',$arrdatetwo),'AND');
        }  

        $Nowpage = $_GET['page']?$_GET['page']:1;
        $limits = 5;// 获取总条数
        $count = M('member_list')->where($map)->count();//计算总页面
        $allpage = ceil($count / $limits);
        $allpage = intval($allpage);
        $lists = M('member_list')->where($map)->page($Nowpage, $limits)->order('m_id desc')->select();
        foreach($lists as $k=>$v)
        {          
            $lists[$k]['birthdate']=date('Y年m月d日',$v['birthdate']);
        }
        $this->assign('Nowpage', $Nowpage);
        $this->assign('allpage', $allpage);
        $this->assign('s',$sldate);
        $this->assign('val',$key);
        //var_dump($_GET['page']);exit;
        if($_GET['page']){
        $this->success($lists);
        }
        $this->display();
    }
	

    public function option()
    {   
       $Model= M('options as o');
       $lists=$Model->join('JOIN lh_user as u ON o.user_id = u.id')->field('o.id as optionid,o.add_time,o.content,u.mobile as mobile,u.truename as truename,u.idcard as idcard')->order('o.add_time DESC')->select();


         $this->assign('lists', $lists);
        $this->display();
    }

    public function editOption($id= 0)
    {
        if ($id = (int)$id) {
            $obj = D('options');
            if (!$detail = $obj -> find($id)) {
                $this -> error('请选择要标记的会员意见');
            }
                $data['id'] = $id;
                $data['status'] =1;

                if ($obj -> save($data)) {
                    $this -> success('操作成功');
                } else {
                    $this -> error('操作失败');
                }

        } else {
            $this -> error('请选择要标记的会员意见');
        }
    }


    public function delOption()
    {  $id=I('id');
      $del= M('options')->delete($id);
      if ($del) {
         exit('1');
      }
    
    }

    public function removesj()
    {   
        $lists=M("jb_records")->select();
        $this->assign('lists',$lists);
        $this->display();
    }
    //解绑审核
       public function editjb($id= 0)
    {
        if ($id = (int)$id) {
            $obj = D('jb_records');
            if (!$detail = $obj -> find($id)) {
                $this -> error('请选择要标记的会员意见');
            }
                $data['id'] = $id;
                $data['jb_status'] =1;

                if ($obj -> save($data)) {
                    $this -> success('操作成功');
                } else {
                    $this -> error('操作失败');
                }

        } else {
            $this -> error('请选择要标记的会员意见');
        }
    }
}